Deployment
Prepare the deployment
To run terraform directly from the gen3-terraform repo you'll need to start by navigating to the directory of the module you want to use. We recommend using the terraform 1.0 commons module. This will provision all the necessary config for a production gen3 instance. If you just want to create a more basic development cluster you can use this module instead.
Once you're in the correct directory, you'll want to make a couple supplemental files to tell terraform how to store the information about the state of your deployment. Create a provider.tf file to tell terraform which cloud we are using.
provider "aws" {}
Next create a backend.tf file, to tell terraform where to store the state file in s3.
terraform {
backend "s3" {
bucket = "s3 bucket name"
encrypt = "true"
key = "directory in bucket/terraform.tfstate"
region = "us-east-1"
}
}
Next take a look at the variables.tf file to see the possible variables you can change. To set the variables you can edit the default values in this file, or more ideally, you can create a config.tfvars file which will set the values for the variables. The file will look like this.
vpc_name="your commons name"
aws_region="us-east-1"
...
Once that is all setup you can proceed to running terraform.
Running terraform
Terraform will run in 2 parts, an initial plan and then an apply. This allows you to see the changes to your infrastructure to prevent unwanted changes that may affect the uptime of your application. Initially it should show only additions, but as you perform maintenance you will likely want to look at the plan more closely to ensure important resources are not deleted or modified.
To create a terraform plan, you can run the following.
terraform plan -var-file config.tfvars
Terraform should automatically pull in all the configuration from any files with a .tf extension in the current directory, as well as all references to the modules referenced in those files. The -var-file flag says to use the variables within the config.tfvars as variables within the module. After running this you should see a plan with a few hundred resources being added to your account.
The next step is to apply these changes if you're happy with them. To do that you can run a similar command, but change plan to apply.
terraform apply -var-file config.tfvars
It will ask you if you want to commit these changes and if you approve them then terraform will run for a while and create the resources.
Note
Terraform may time out creating resources or run into errors. If it does, it can be normal due to long provisioning processes and race conditions. If you see errors run apply a couple more times and if the errors persist, reach out over our community slack channel ffor assistance.